﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MediaPlayer;

namespace SimpleMediaPlayer
{
    public partial class MediaInfomation : Form
    {
        private Player player { get; set; }

        public MediaInfomation(Player player)
        {
            this.player = player;

            InitializeComponent();
        }

        private void MediaInfomation_Load(object sender, EventArgs e)
        {
            if (this.player.Type != MediaType.None)
            {
                listViewMetadata.Items.Add(new ListViewItem(new string[] { "Location", this.player.File }));

                //getPropertyItem("Track name");
                //getPropertyItem("Album");
                //getPropertyItem("Track name/Position", "Track number");
                //getPropertyItem("Performer", "Artist");
                //getPropertyItem("Recorded date", "Year");
                //getPropertyItem("Genre");
                //getPropertyItem("Album replay gain");
                //getPropertyItem("Album replay gain peak");

                foreach (var property in this.player.MediaFile.Metadata)
                {
                    getPropertyItem(property.Key);
                }
            }

            if (this.player.MediaFile.Art != null)
            {
                pictureBoxArt.Image = this.player.MediaFile.Art;
            }
        }

        private void getPropertyItem(string property, string title = "")
        {
            if (this.player.MediaFile.Metadata[property] != null)
            {
                if (title == "")
                {
                    title = property;
                }

                listViewMetadata.Items.Add(new ListViewItem(new string[] { title, this.player.MediaFile.Metadata[property] }));
            }
        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
